package com.ruoyi.web.controller.yf;

import java.util.List;

import com.ruoyi.yf.service.IYfMedicalWasteAndHospitalRelationshipService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yf.domain.YfMedicalWasteTreatmentManager;
import com.ruoyi.yf.service.IYfMedicalWasteTreatmentManagerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 第三方医废处置公司详细信息管理Controller
 *
 * @author XiaoYi...
 * @date 2020-08-14
 * d0f06c25-595d-476b-ad5e-4a96ba49e4df
 */
@Controller
@RequestMapping("/yf/wasteTreatment")
public class YfMedicalWasteTreatmentManagerController extends BaseController {
    private String prefix = "yf/wasteTreatment";

    @Autowired
    private IYfMedicalWasteTreatmentManagerService yfMedicalWasteTreatmentManagerService;

    @RequiresPermissions("yf:wasteTreatment:view")
    @GetMapping()
    public String wasteTreatment() {
        return prefix + "/wasteTreatment";
    }

    /**
     * 查询第三方医废处置公司详细信息管理列表
     * 5c6c0c89-1063-4c8f-a698-62a99e6cf5a7
     */
    @RequiresPermissions("yf:wasteTreatment:list")
    @RequestMapping(value = "/list")
    @ResponseBody
    public TableDataInfo list(YfMedicalWasteTreatmentManager yfMedicalWasteTreatmentManager) {
        startPage();
        List<YfMedicalWasteTreatmentManager> list = yfMedicalWasteTreatmentManagerService.selectYfMedicalWasteTreatmentManagerList(yfMedicalWasteTreatmentManager);
        return getDataTable(list);
    }

    /**
     * 导出第三方医废处置公司详细信息管理列表
     * 3cb7ccce-3b32-49fa-bf06-e8d2ed0424ae
     */
    @RequiresPermissions("yf:wasteTreatment:export")
    @Log(title = "第三方医废处置公司详细信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YfMedicalWasteTreatmentManager yfMedicalWasteTreatmentManager) {
        List<YfMedicalWasteTreatmentManager> list = yfMedicalWasteTreatmentManagerService.selectYfMedicalWasteTreatmentManagerList(yfMedicalWasteTreatmentManager);
        ExcelUtil<YfMedicalWasteTreatmentManager> util = new ExcelUtil<YfMedicalWasteTreatmentManager>(YfMedicalWasteTreatmentManager.class);
        return util.exportExcel(list, "wasteTreatment");
    }

    /**
     * 新增第三方医废处置公司详细信息管理
     * 8ace2404-34ed-4ae8-9a33-aa875eecf0e7
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 802aeb11-7b0b-4484-ae1b-3e24d3eb88bb
     * 新增保存第三方医废处置公司详细信息管理
     */
    @RequiresPermissions("yf:wasteTreatment:add")
    @Log(title = "第三方医废处置公司详细信息管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YfMedicalWasteTreatmentManager yfMedicalWasteTreatmentManager) {
        return toAjax(yfMedicalWasteTreatmentManagerService.insertYfMedicalWasteTreatmentManager(yfMedicalWasteTreatmentManager));
    }

    /**
     * 修改第三方医废处置公司详细信息管理
     * 07959c44-c1b5-4825-b972-6175c22237de
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        YfMedicalWasteTreatmentManager yfMedicalWasteTreatmentManager = yfMedicalWasteTreatmentManagerService.selectYfMedicalWasteTreatmentManagerById(id);
        mmap.put("yfMedicalWasteTreatmentManager", yfMedicalWasteTreatmentManager);
        return prefix + "/edit";
    }

    /**
     * 修改保存第三方医废处置公司详细信息管理
     * 658f05cb-ac2f-41ab-b444-dd00c6b13f78
     */
    @RequiresPermissions("yf:wasteTreatment:edit")
    @Log(title = "第三方医废处置公司详细信息管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YfMedicalWasteTreatmentManager yfMedicalWasteTreatmentManager) {
        return toAjax(yfMedicalWasteTreatmentManagerService.updateYfMedicalWasteTreatmentManager(yfMedicalWasteTreatmentManager));
    }

    @Autowired
    private IYfMedicalWasteAndHospitalRelationshipService yfMedicalWasteAndHospitalRelationshipService;

    /**
     * 7f321e48-0242-4c80-8578-43580bdbb4a9
     * 删除第三方医废处置公司详细信息管理
     */
    @RequiresPermissions("yf:wasteTreatment:remove")
    @Log(title = "第三方医废处置公司详细信息管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        int sum = yfMedicalWasteAndHospitalRelationshipService.selectRelationshipSum(ids);
        if (sum >= 0)
            return error("已签订合同不允许删除");
        return toAjax(yfMedicalWasteTreatmentManagerService.deleteYfMedicalWasteTreatmentManagerByIds(ids));
    }
}
